package com.loe.test

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import com.loe.ktui.*
import com.loe.ktui.util.KtColor
import com.loe.ktui.util.KtFragItem
import kotlinx.android.synthetic.main.activity_test.*

class TestActivity : AppCompatActivity()
{
    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)


        textView.bindHtml = "我的名字\n叫<font color='#FF8800'><b>{name}</b></font>，今年{age}岁了。"
        var age by textView.bind("age")

        button.setOnClickListener()
        {
            textView["name"] = "顺哥哥"
            age = "3333"
        }


        tabView.setOnItemSelect()
        { view, isSelect, i, bean ->
            view as KtTextView
            view.setTextColor(if (isSelect) KtColor.red else KtColor.text)
        }

//        cameraImageView.src = "https://img2.baidu.com/it/u=1737067577,8701429&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889"
        cameraImageView.src = "https://img2.baidu.com/it/u=1110941159,2287283460&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"

        tabView.datas = listOf("简传递单", "谁是说的", "是啊", "广告")
//        viewPager.setFragItems(
//            listOf(
//                KtFragItem(TestFragment::class).addArg("name", "时代光华海上风电"),
//                KtFragItem(TestFragment::class).addArg("name", "神鼎飞丹砂"),
//                KtFragItem(TestFragment::class).addArg("name", "发发发发发"),
//                KtFragItem(TestFragment::class).addArg("name", "发的发的方法"),
//                KtFragItem(TestFragment::class),
//            )
//        )


//        tabView.datas = listOf("简传递单", "谁是说的", "是啊")
//        viewPager.setFragItems(
//            listOf(
//                KtFragItem(TestFragment::class).addArg("name", "顺哥哥00111"),
//                KtFragItem(TestFragment::class).addArg("name", "顺哥哥122"),
//                KtFragItem(TestFragment::class).addArg("name", "顺哥哥133"),
//                KtFragItem(TestFragment::class).addArg("name", "顺哥哥144"),
//                KtFragItem(TestFragment::class),
//            )
//        )

//        ktHandler.postDelayed({
//            tabView.datas = listOf("111", "222", "3333", "啊实打实3333")
//
//            viewPager.currentItem = 1
//        }, 3000)

//        tabView.viewPager = viewPager
//        drawerlayout.openDrawer(Gravity.LEFT)

//        val list = arrayListOf(
//            "所发生的丰富的斯柯达经济开发金粉世家",
//            "富东饭店",
//            "地方",
//            "经济",
//            "风风光光",
//            "来看待",
//            "的",
//            "快捷键快递费",
//            "丰富的",
//            "发方法",
//        )
//
//        recyclerView.adapter = object: BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_test, list)
//        {
//            override fun convert(holder: BaseViewHolder, s: String)
//            {
//                holder.itemView.textView.text = s
//            }
//        }

        val listView = ui_List<String>()
        {
            type = UiList.TYPE_GRID
            spanCount = 2
            bg = KtColor.white
            isScroll = false

            itemUI = ui_FrameLayout()
            {
                ui_Image()
                {
                    id = "image"
                    height = 112
                    corner = 3
                    scaleType = ImageView.ScaleType.CENTER_CROP
                    src = "https://img2.baidu.com/it/u=794528275,4064511912&fm=253&fmt=auto&app=138&f=JPEG?w=789&h=500"
                }
            }

            itemConvert()
            { adapter, holder, bean ->
                val image = findView<KtImageView>("image")
                image.src = bean
            }

//            datas = listOf("223是的是的", "大多都是", "刷卡说的就是", "第三方付", "疯疯癫癫", "大幅度", "方法", "是多少顺丰到付", "大多都是", "刷卡说的就是", "第三方付", "疯疯癫癫", "大幅度", "方法", "是多少顺丰到付")
//
//            onCreateView()
//            {
////                    setData(arrayListOf("3332稍等", "好的"))
//            }
        }.createListView(this)

        listView.setData(listOf("223是的是的", "大多都是", "刷卡说的就是", "第三方付", "疯疯癫癫", "大幅度", "方法"))
        viewRoot.addView(listView)
    }
}